﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Net.Mail;

public partial class mail : System.Web.UI.Page
{
    
    protected void Page_Load(object sender, EventArgs e)
    {
        //Label lblError = (Label)FormView1.FindControl("lblError"); 
        //lblError.Visible = false;
        
    }
    protected void InsertButton_Click(object sender, EventArgs e)
    {
        TextBox Name = (TextBox)FormView1.FindControl("txtName");
        string Name1 = Name.Text;
        TextBox Mail = (TextBox)FormView1.FindControl("txtMail");
        string Mail1 = Mail.Text;
        TextBox Emne = (TextBox)FormView1.FindControl("txtEmne");
        string Emne1 = Emne.Text;
        TextBox Text = (TextBox)FormView1.FindControl("txtText");
        string Text1 = Text.Text;
        //Label lblError = (Label)FormView1.FindControl("lblError"); 
        try
        {
            MailMessage mail = new MailMessage();
            SmtpClient smtp = new SmtpClient("10.138.22.47");

            mail.From = new MailAddress(Mail1);
            mail.To.Add("kf109074@elev.mediacollege.dk");

            mail.Subject = "Contact From:" + Name1;
            mail.IsBodyHtml = true;
            string htmlbody = "<html><body>Message From" + Name1 + "<br/>Mail:" + Mail1 + "<br/>Emne:" + Emne1 + "<br/><br/>" + "Message:" + Text1 + "<br/><br/>";
            mail.Body = htmlbody;
            smtp.Send(mail);
            lblError.Text = "Your Mail is sent";
            lblError.Visible = true;
        }

        catch (Exception)
        {
            lblError.Text = "There went something wrong. Please try again";
            lblError.Visible = true;
        }
        Response.AddHeader("Refresh", "15; url=Default.aspx");
    }
}